package com.qingzhu.controller.addressserver;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.qingzhu.pojovo.ResultVo;
import com.qingzhu.service.ReceivingAddressService;
import com.qingzhu.service.impl.ReceivingAddressServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/receiving/address/del")
public class ReceivingAddressDeleteController extends HttpServlet {
    ObjectMapper objectMapper = new ObjectMapper();
    ReceivingAddressService receivingAddressService = new ReceivingAddressServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        try {
            receivingAddressService.delOneReceivingAddress(Integer.parseInt(id));
            resp.getWriter().write(objectMapper.writeValueAsString(new ResultVo(200, "删除成功！")));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
